package com.xuecheng.checkcode.controller;

import com.xuecheng.checkcode.model.CheckCodeParamsDto;
import com.xuecheng.checkcode.model.CheckCodeResultDto;
import com.xuecheng.checkcode.service.CheckCodeService;
import com.zzb.base.model.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Mr.M
 * @version 1.0
 * @description 验证码服务接口
 * @date 2022/9/29 18:39
 */
@Api(value = "验证码服务接口")
@RestController
public class CheckCodeController {

    @Resource(name = "PicCheckCodeService")
    private CheckCodeService checkCodeService;

    /**
     * 生成验证信息
     * @param checkCodeParamsDto
     * @return
     */
    @ApiOperation(value = "生成验证信息", notes = "生成验证信息")
    @PostMapping(value = "/pic")
    public CheckCodeResultDto generatePicCheckCode(CheckCodeParamsDto checkCodeParamsDto) {
        return checkCodeService.generate(checkCodeParamsDto);
    }

    /**
     * 校验验证码
     * @param key
     * @param code
     * @return
     */
    @ApiOperation(value = "校验", notes = "校验")
    @PostMapping(value = "/verify")
    public Boolean verify(@RequestParam String key, @RequestParam String code) {
        return checkCodeService.verify(key, code);
    }

    /**
     * 发送验证码
     * @param checkCodeParamsDto
     * @return
     */
    @ApiOperation(value = "发送验证码", notes = "发送验证码")
    @PostMapping(value = "/phone")
    public RestResponse<Boolean> getPhoneSms(CheckCodeParamsDto checkCodeParamsDto) {
        Boolean code = checkCodeService.getPhoneSms(checkCodeParamsDto);
        return RestResponse.ok(code);
    }
}
